import { deleteByPrimaryKeyForProSystemAuth, selectByPrimaryKeyForProSystemAuth, insertForProSystemAuth, updateForProSystemAuth, deleteByMapForProSystemAuth,updateByMapForProSystemAuth, getOneForProSystemAuth,getAllForProSystem,queryPageForProSystem, countForProSystemAuth, insertBatchForProSystemAuth, deleteBatchForProSystemAuth,updateBatchForProSystemAuth,getPageProSystemByAuthId,queryPageForProAuthority,queryPageForProSystemChild,getSelectedProSystemByAuthId } from '@/services/system/api_prosystemauth';

export default {
    namespace: 'prosystemauth',

    state: {
        data: {
            list: [],
            pagination: {},
        },
   		system: {
   			list: [],
            pagination: {},
   		},
   		systemChild: {
   			list: [],
            pagination: {},
   		},
   		systemSelect: {
   			list: [],
   		}
    },

    effects: {
            *delete_by_primarykey_for_prosystemauth({ payload }, { call, put }) {
                const response = yield call(deleteByPrimaryKeyForProSystemAuth, payload);
                yield put({
                    type: 'deleteByPrimaryKeyForProSystemAuth',
                    payload: response,
                });
            },
            *select_by_primarykey_for_prosystemauth({ payload, callback }, { call, put }) {
                const response = yield call(selectByPrimaryKeyForProSystemAuth, payload);
                yield put({
                    type: 'selectByPrimaryKeyForProSystemAuth',
                    payload: response,
                });
                if (callback) callback();
            },
            *insert_for_prosystemauth({ payload, callback }, { call, put }) {
                const response = yield call(insertForProSystemAuth, payload);
                yield put({
                    type: 'insertForProSystemAuth',
                    payload: response,
                });
                if (callback) callback();
            },
            *update_for_prosystemauth({ payload, callback }, { call, put }) {
                const response = yield call(updateForProSystemAuth, payload);
                yield put({
                    type: 'updateForProSystemAuth',
                    payload: response,
                });
                if (callback) callback();
            },
            *delete_by_map_for_prosystemauth({ payload, callback }, { call, put }) {
                const response = yield call(deleteByMapForProSystemAuth, payload);
                yield put({
                    type: 'deleteByMapForProSystemAuth',
                    payload: response,
                });
                if (callback) callback();
            },
            *update_by_map_for_prosystemauth({ payload, callback }, { call, put }) {
                const response = yield call(updateByMapForProSystemAuth, payload);
                yield put({
                    type: 'updateByMapForProSystemAuth',
                    payload: response,
                });
                if (callback) callback();
            },
            *get_one_for_prosystemauth({ payload, callback }, { call, put }) {
                const response = yield call(getOneForProSystemAuth, payload);
                yield put({
                    type: 'getOneForProSystemAuth',
                    payload: response,
                });
                if (callback) callback();
            },
            *get_all_for_prosystem({ payload, callback }, { call, put }) {
                const response = yield call(getAllForProSystem, payload);
                yield put({
                    type: 'getAllForProSystem',
                    payload: response,
                });
                if (callback) callback();
            },
            *query_page_for_prosystem({ payload, callback }, { call, put }) {
                const response = yield call(queryPageForProSystem, payload);
                yield put({
                    type: 'queryPageForProSystem',
                    payload: response,
                });
                if (callback) callback();
            },
            *count_for_prosystemauth({ payload, callback }, { call, put }) {
                const response = yield call(countForProSystemAuth, payload);
                yield put({
                    type: 'countForProSystemAuth',
                    payload: response,
                });
                if (callback) callback();
            },
            *insert_batch_for_prosystemauth({ payload, callback }, { call, put }) {
                const response = yield call(insertBatchForProSystemAuth, payload);
                yield put({
                    type: 'insertBatchForProSystemAuth',
                    payload: response,
                });
                
                const responsedata = yield call(queryPageForProAuthority, {});
                yield put({
                	type: 'queryPageForProAuthority',
                	payload: responsedata,
                });
                
                const newPayload = { auth_id: [payload.authids[0].id]};
                const responseSystem = yield call(getPageProSystemByAuthId, newPayload);
                yield put({
                    type: 'getPageProSystemByAuthId',
                    payload: responseSystem,
                });
                
                if (callback) callback();
            },
            *delete_batch_for_prosystemauth({ payload, callback }, { call, put }) {
                const response = yield call(deleteBatchForProSystemAuth, payload);
                yield put({
                    type: 'deleteBatchForProSystemAuth',
                    payload: response,
                });
                if (callback) callback();
            },
            *update_batch_for_prosystemauth({ payload, callback }, { call, put }) {
                const response = yield call(updateBatchForProSystemAuth, payload);
                yield put({
                    type: 'updateBatchForProSystemAuth',
                    payload: response,
                });
                if (callback) callback();
            },
            *get_page_prosystem_by_authid({ payload, callback }, { call, put }) {
                const response = yield call(getPageProSystemByAuthId, payload);
                yield put({
                    type: 'getPageProSystemByAuthId',
                    payload: response,
                });
                if (callback) callback();
            },
            *query_page_for_proauthority({ payload, callback }, { call, put }) {
                const response = yield call(queryPageForProAuthority, payload);
                yield put({
                    type: 'queryPageForProAuthority',
                    payload: response,
                });
                if (callback) callback();
            },
            *query_page_for_prosystemchild({ payload, callback }, { call, put }) {
                const response = yield call(queryPageForProSystemChild, payload);
                yield put({
                    type: 'queryPageForProSystemChild',
                    payload: response,
                });
                if (callback) callback();
            },
            *get_selected_prosystem_by_authid({ payload, callback }, { call, put }) {
                const response = yield call(getSelectedProSystemByAuthId, payload);
                yield put({
                    type: 'getSelectedProSystemByAuthId',
                    payload: response,
                });
                if (callback) callback();
            },
            },

    reducers: {
        deleteByPrimaryKeyForProSystemAuth(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        selectByPrimaryKeyForProSystemAuth(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        insertForProSystemAuth(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        updateForProSystemAuth(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        deleteByMapForProSystemAuth(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        updateByMapForProSystemAuth(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        getOneForProSystemAuth(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        getAllForProSystem(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        queryPageForProSystem(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        countForProSystemAuth(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        insertBatchForProSystemAuth(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        deleteBatchForProSystemAuth(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        updateBatchForProSystemAuth(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        getPageProSystemByAuthId(state, action) {
            return {
                ...state,
                system: action.payload,
            };
        },
        queryPageForProAuthority(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        queryPageForProSystemChild(state, action) {
            return {
                ...state,
                systemChild: action.payload,
            };
        },
        getSelectedProSystemByAuthId(state, action) {
            return {
                ...state,
                systemSelect: action.payload,
            };
        },
    },
};
